﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Faust.Andrew.MTG.Player
{
	/// <summary>
	/// Interaction logic for HostGameConfigurationWindow.xaml
	/// </summary>
	public partial class HostGameConfigurationWindow : Window
	{
        public int Port
        {
            get
            {
                int port;
                if (Int32.TryParse(txtPort.Text, out port))
                {
                    return port;
                }
                else
                {
                    return -1;
                }
            }            
        }

        public new string Name
        {
            get { return joinConfiguration.Name; }            
        }

        public string DeckName
        {
            get { return joinConfiguration.DeckName; }
        }

        public List<string> Decks
        {
            set { joinConfiguration.Decks = value; }
        }

        public bool UsePlanes
        {
            get
            {
                return (chkUsePlanes.IsChecked == true);
            }
        }

        public HostGameConfigurationWindow()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}

        private bool Validate()
        {
            if (Port < 0)
            {
                MessageBox.Show("You must enter a port between 0-65535");
                return false;
            }

            return joinConfiguration.Validate();
        }

		private void btnCancel_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            DialogResult = false;
            Close();
		}

		private void btnOK_Click(object sender, System.Windows.RoutedEventArgs e)
		{
            if (Validate())
            {
                DialogResult = true;
                Close();
            }
		}

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            joinConfiguration.ShowHostInformation = false;
        }
	}
}